package com.redsun.smallworld.gl.controls;

import com.redsun.smallworld.gl.controls.moudle.ControlInfo;
import com.redsun.smallworld.gl.controls.parent.SuperControl;
import com.redsun.smallworld.gl.glcontroller.TextureController;

import javax.media.opengl.GL;
import javax.media.opengl.GL2;

/**
 * Created by zhebinwang on 2017/6/2.
 */
public class OButton extends SuperControl {



    public  OButton(ControlInfo controlInfo){
        this.setHeight(controlInfo.getHeight()).setWidth(controlInfo.getWidth())
                .setX(controlInfo.getX()).setY(controlInfo.getY())
                .setTexindex(controlInfo.getTexindex())
                .setTexheight(controlInfo.getTexheight()).setTexwidth(controlInfo.getTexwidth())
                .setTexu(controlInfo.getTexu()).setTexv(controlInfo.getTexv());

    }
    public OButton(){

    }

    @Override
    public int doRender(GL2 gl2) {

        gl2.glBindTexture(GL.GL_TEXTURE_2D, TextureController.textureid[getTexindex()]);

        gl2.glBegin(GL2.GL_QUADS);
        // 左下
        gl2.glTexCoord2f(texu, texv+texwidth);               gl2.glVertex2f(x, y);
        // 右下
        gl2.glTexCoord2f(texu+texheight, texv+texwidth);  gl2.glVertex2f(x+width, y);
        // 右上
        gl2.glTexCoord2f(texu+texheight, texv);               gl2.glVertex2f(x+width, y+height);
        // 左上
        gl2.glTexCoord2f(texu, texv);                            gl2.glVertex2f(x, y+height);
        gl2.glEnd();
        return 0;
    }
}
